
/*
 *************************************************************************
 *西瑞克斯研发管理系统
 *版 本: 1.0   
 *日 期：02/08/2012    
 *作 者： 王浩 QQ：873987060   
 *************************************************************************   
 */
package com.application.summary2moon.struts.actions;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.manager.commons.config.ConfigFactory;
import com.manager.commons.page.PageBean;
import com.manager.commons.CurrentUserUtils;
import com.manager.commons.RandomKey;
import com.manager.commons.CommonUtil;
import com.application.attachment.entity.Attachment;
import com.application.attachment.service.AttachmentService;
import com.application.attachment.struts.form.AttachmentForm;
import com.application.role.entity.Role;
import com.application.summary2moon.entity.Summary2moon;
import com.application.summary2moon.struts.form.Summary2moonForm;
import com.application.summary2moon.service.Summary2moonService;
import com.application.summary2moon.commons.Constants;
import com.application.usertable.entity.Usertable;

/**
 * 
 * Description:Summary2moonAction<br />
 * 
 * Version:V0.1<br />
 * 
 * Author: 王浩 QQ：873987060 <br />
 * 
 * History: <br />
 * 
 * 02/08/2012
 * 
 */
public class Summary2moonAction extends DispatchAction {

	/**
	 * Service层实例
	 */
	private Summary2moonService summary2moonService;
	private AttachmentService attachmentService;

	/**
	 * 日志
	 */
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * 实体对象
	 */
	private Summary2moon summary2moon;

	/**
	 * 采用partialList方式分页程序
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public ActionForward getSummary2moonPartialList(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("searchSummary2moon" + "开始");
		Summary2moonForm summary2moon = (Summary2moonForm) form;
		// 统计总记录数的sql语句
		int resultSize = 0;
		// 初始化pageBean供分页所用
		PageBean pageBean = null;
		// 取得当前页list数据
		List summary2moonList = null;
		resultSize = summary2moonService.getAllCountSummary2moon(summary2moon);
		pageBean = PageBean.getPageBean("summary2moonTab", resultSize, request);
		summary2moonList = summary2moonService.searchSummary2moon(summary2moon,
				pageBean);
		request.setAttribute("summary2moonList", summary2moonList);
		request.setAttribute("orgSelect", CommonUtil.getOrgSelectNoZB());
		request.setAttribute("yearSelect", CommonUtil.getYearSelect());
		request.setAttribute("moonSelect", CommonUtil.getMoon());
		Usertable user = CurrentUserUtils.getCurrentUser();
		String addQx="noAdd";
		List<Role>  role = user.getRoleList();
		for(int i=0;i<role.size();i++){
			if(role.get(i).getName().equals("研发经理")||role.get(i).getName().equals("研发中心负责人")){
				addQx="Add";
			}
		}
		request.setAttribute("addQx", addQx);
		log.debug("searchSummary2moon" + "结束");

		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达新增页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toAddSummary2moon(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("toAddSummary2moons");
		Date date = new Date();
		Summary2moonForm summary2moonForm = new Summary2moonForm();
		summary2moonForm.setId(RandomKey.generateID_Long_19());
		summary2moonForm.setCreatedate(date);
//		request.setAttribute("yearSelect", CommonUtil.getYearSelect());
//		request.setAttribute("moonSelect", CommonUtil.getMoon());
		request.setAttribute("summary2moonForm", summary2moonForm);
		request.setAttribute("kg", CommonUtil.getKz());

		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 增加
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward addSummary2moon(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("addSummary2moons");
		Summary2moon summary2moon = this.getSummary2moon(form);
		summary2moon.setCreatedate(new Date());
		this.summary2moonService.insertObject(summary2moon);
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 删除
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward deleteSummary2moon(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("deleteSummary2moons");
		Summary2moonForm summary2moonForm = (Summary2moonForm) form;
		this.summary2moonService.deleteSummary2moons(summary2moonForm);
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 到达更新页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward toUpdateSummary2moon(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("toUpdateSummary2moons");
		Summary2moonForm summary2moonForm = (Summary2moonForm) form;
		summary2moon = (Summary2moon) this.summary2moonService.searchSummary2moon(
				summary2moonForm).get(0);
		request.setAttribute(Constants.DEPARTMENT, summary2moon);
		request.setAttribute("kg", CommonUtil.getKz());
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 更新
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward updateSummary2moon(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		log.debug("updateSummary2moons");
		Summary2moon summary2moon = this.getSummary2moon(form);
		summary2moon.setCreatedate(new Date());
		this.summary2moonService.updateObject(summary2moon);
		
		return mapping.findForward(Constants.SUCCESS);
	}

	/**
	 * 查看页面
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward viewSummary2moon(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("viewSummary2moon");
		Summary2moonForm summary2moonForm = (Summary2moonForm) form;
		summary2moon = (Summary2moon) this.summary2moonService.searchSummary2moon(
				summary2moonForm).get(0);
		request.setAttribute(Constants.DEPARTMENT, summary2moon);
		request.setAttribute("kg", CommonUtil.getKz());
		return mapping.findForward(Constants.SUCCESS);
	}
	
	/**
	 * 打分
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return ActionForward
	 * @throws Exception
	 */
	public ActionForward dfSummary2moon(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		log.debug("viewSummary2moon");
		Summary2moonForm summary2moonForm = (Summary2moonForm) form;
		summary2moon = (Summary2moon) this.summary2moonService.searchSummary2moon(
				summary2moonForm).get(0);
		summary2moon.setDf(summary2moonForm.getDf());
		summary2moon.setBak1(summary2moonForm.getBak1());
		this.summary2moonService.updateObject(summary2moon);
		return mapping.findForward(Constants.SUCCESS);
	}
	// get--set
	/**
	 * @return the Summary2moonService
	 */
	public Summary2moonService getSummary2moonService() {
		return this.summary2moonService;
	}

	/**
	 * @param Summary2moonService
	 *            the Summary2moonService to set
	 */
	public void setSummary2moonService(Summary2moonService summary2moonService) {
		this.summary2moonService = summary2moonService;
	}

	/**
	 * 获取Summary2moon实体
	 * 
	 * @param ActionForm
	 * @throws InvocationTargetException
	 * @throws IllegalAccessException
	 * @return the Summary2moon
	 */
	public Summary2moon getSummary2moon(ActionForm form)
			throws IllegalAccessException, InvocationTargetException {
		Summary2moonForm summary2moonForm = (Summary2moonForm) form;
		summary2moon = new Summary2moon();
		BeanUtils.copyProperties(summary2moon, summary2moonForm);
		return summary2moon;
	}

	public void setSummary2moon(Summary2moon summary2moon) {
		this.summary2moon = summary2moon;
	}

	/**
	 * @return the attachmentService
	 */
	public AttachmentService getAttachmentService() {
		return attachmentService;
	}

	/**
	 * @param attachmentService the attachmentService to set
	 */
	public void setAttachmentService(AttachmentService attachmentService) {
		this.attachmentService = attachmentService;
	}

	/**
	 * @return the summary2moon
	 */
	public Summary2moon getSummary2moon() {
		return summary2moon;
	}


}
